﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        loadModules();
        searchResult();
    }
    protected void loadModules()
    {
        phd_menu.Controls.Clear();
        UserControl uc = (UserControl)LoadControl("./modules/menu.ascx");
        phd_menu.Controls.Add(uc);

        /*phd_banner.Controls.Clear();
        UserControl uc_banner = (UserControl)LoadControl("./modules/banner.ascx");
        phd_banner.Controls.Add(uc_banner);

        phd_search.Controls.Clear();
        UserControl uc_search = (UserControl)LoadControl("./modules/search.ascx");
        phd_search.Controls.Add(uc_search);

        /*phd_flash_logo.Controls.Clear();
        UserControl uc_flash_logo = (UserControl)LoadControl("./modules/flash_logo.ascx");
        phd_search.Controls.Add(uc_flash_logo);*/

        /* phd_foreside_content.Controls.Clear();
         UserControl uc_foreside_content = (UserControl)LoadControl("./modules/foreside_content.ascx");
         phd_foreside_content.Controls.Add(uc_foreside_content);*/
    }
    protected void searchResult() {
        try {
            int catid = Convert.ToInt32(Request.QueryString["catid"]);
            int postnumber = Convert.ToInt32(Request.QueryString["postnumber"]);
            string query = "SELECT * FROM mwc_house WHERE catid = " + catid + " AND postnumber = " + postnumber ;
            SqlConnection sc = new SqlConnection(ConfigurationSettings.AppSettings["mwc_con"]);
            sc.Open();
            SqlCommand scmd = new SqlCommand(query, sc);
            SqlDataReader sdr = scmd.ExecuteReader();
            while (sdr.Read()) {
                Label lb = new Label();
                string sale_lease = (sdr["sale_lease"] == "1") ? "Salg" : "Leje";
                lb.Text  = "<div class=\"box_imgland\">";
                lb.Text += "      <p class=\"p10b font_13_bo\"><a href=\"produktion_more2.html\">" + sdr["address"] + "</a></p>";
                lb.Text += "      <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
                lb.Text += "       <tr>";
                lb.Text += "          <td width=\"21%\"><a href=\"produktion_more2.html\"><img src=\"" + sdr["image"] + "\" width=\"191\"/></a></td>";
                lb.Text += "          <td class=\"sty_table\" width=\"28%\">" + sdr["introtext"] + "</td>";
                lb.Text += "          <td class=\"sty_table\" width=\"16%\">" + sdr["address"] + "</td>";
                lb.Text += "           <td class=\"sty_table\" width=\"12%\">" + sdr["postnumber"] + "</td>";
                lb.Text += "           <td class=\"sty_table\" width=\"11%\">" + sdr["area"] + "</td>";
                lb.Text += "           <td class=\"sty_table\" width=\"12%\">" + sale_lease + "</td>";
                lb.Text += "         </tr>";
                lb.Text += "       </table>";
                lb.Text += "     </div>";
                pn_house_list.Controls.Add(lb);
            }
            sc.Close();

        }
        catch (Exception e) {
            Response.Redirect("Default.aspx");
        }
    }

}
